<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-paperclip"></i> 友链管理 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="tableData"
                border
                class="table"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" width="80" label="ID"></el-table-column>
                <el-table-column prop="tagName" width="80" label="分类名称"></el-table-column>
                <el-table-column prop="linkDesc" label="链接描述"></el-table-column>
                <el-table-column prop="linkAddress" label="链接地址"></el-table-column>
                <el-table-column prop="issueTime" label="发布时间"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-delete" class="red" @click="handleDelete(scope.$index, scope.row)"
                            >删除</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.current"
                    :page-size="query.size"
                    :total="query.total"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { list,delLink} from '../../api/Link.js';
export default {
    data() {
        return {
            query: {
                current: 1,
                size: 10,
                total: 0
            },
            tableData: [],
            params: {
                uid: '',
                token: ''
            },
            formLabelWidth: '120px',
        };
    },
    created() {
        this.params.uid = this.$cookies.get('uid');
        this.params.token = this.$cookies.get('token');
        this.getPage();
    },
    methods: {
        //分页查询
        getPage() {
            list(this.query,this.params)
                .then((res) => {
                    if (res.code==200) {
                        this.query.current = res.data.current;
                        this.query.size = res.data.size;
                        this.query.total = res.data.total;
                        this.tableData = res.data.records;
                    }
                })
        },
        // 触发搜索按钮
        handleSearch() {
            this.getPage();
        },
        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    delLink(row,this.params)
                        .then((res) => {
                            if (res.code==200) {
                                this.$notify({
                                    title: '成功',
                                    message: res.msg,
                                    type: 'success'
                                });
                                this.tableData.splice(index, 1);
                            }else{
                                this.$notify({
                                    title: '失败',
                                    message: res.msg,
                                    type: 'error'
                                }); 
                            }
                        })
                })
                .catch(() => {});
        },
        // 分页导航
        handlePageChange(val) {
            this.query.current = val;
            this.getPage();
        }
    }
};
</script>

<style scoped>
.header {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    height: 70px;
    font-size: 22px;
    color: #fff;
}
.collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;
    line-height: 70px;
}
.header .logo {
    float: left;
    width: 200px;
    padding-left: 35px;
    line-height: 70px;
}
.header-right {
    float: right;
    padding-right: 50px;
}
.header-user-con {
    display: flex;
    height: 70px;
    align-items: center;
}
.btn-fullscreen {
    transform: rotate(45deg);
    margin-right: 5px;
    font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
    position: relative;
    width: 30px;
    height: 30px;
    text-align: center;
    border-radius: 15px;
    cursor: pointer;
}
.btn-bell-badge {
    position: absolute;
    right: 0;
    top: -2px;
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #f56c6c;
    color: #fff;
}
.btn-bell .el-icon-bell {
    color: #fff;
}
.user-name {
    margin-left: 10px;
}
.user-avator {
    margin-left: 20px;
}
.user-avator img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
}
.el-dropdown-link {
    color: #fff;
    cursor: pointer;
}
.el-dropdown-menu__item {
    text-align: center;
}
.content-title {
    font-weight: 400;
    line-height: 50px;
    margin: 10px 0;
    font-size: 22px;
    color: #1f2f3d;
}
.pre-img {
    width: 80px;
    height: 80px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 40px;
}
.crop-demo {
    display: flex;
    align-items: flex-end;
}
.crop-demo-btn {
    position: relative;
    width: 80px;
    height: 30px;
    line-height: 30px;
    padding: 0 15px;
    margin-left: 20px;
    margin-bottom: 25px;
    background-color: #409eff;
    color: #fff;
    font-size: 12px;
    border-radius: 4px;
    box-sizing: border-box;
}
.crop-input {
    position: absolute;
    width: 100px;
    height: 40px;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
